**************************************************************
*** NLSY97: recode ***
**************************************************************

cd "SET_YOUR_OUTPATH\NLSY97"

use "SET_YOUR_INPATH\NLSY97\nlsy97.dta", clear

drop CV_SAMPLE_TYPE* KEY_BDATE_M_1997

*** rename variables

rename KEY_SEX_1997 sex
rename PUBID_1997 pid
rename KEY_BDATE_Y_1997 birthyear 
*rename SIDCODE_1997 sidcode
rename CVC_WKSWK_TEEN2_XRND wkswk_teen
rename CVC_WKSWK_ADULT2_ET_XRND wkswk_adult_et
rename CVC_WKSWK_ADULT2_ALL_XRND wkswk_adult_all
rename CVC_HGC_EVER_XRND highest_grade
rename CVC_HIGHEST_DEGREE_EVER_XRND highest_degree
rename YOUTH_ADOPDADID_01_1997 dad_adopt_id
rename YOUTH_ADOPMOMID_01_1997 mom_adopt_id
rename YOUTH_DADID_01_1997 dad_id
rename YOUTH_FOSTDADID_01_1997 dad_fost_id
rename YOUTH_FOSTMOMID_01_1997 mom_fost_id
rename YOUTH_MOMID_01_1997 mom_id
rename YOUTH_PARENTID_01_1997 parent_id
rename CV_HGC_BIO_DAD_1997 dad_highest_grade
rename CV_HGC_BIO_MOM_1997 mom_highest_grade
rename CV_HGC_RES_DAD_1997 dad_res_highest_grade
rename CV_HGC_RES_MOM_1997 mom_res_highest_grade

rename CV_HH_SIZE_* hhsize_* 
rename KEY_RACE_ETHNICITY_1997 ethnicity
rename CV_INCOME_GROSS_YR_* faminc_*
rename CV_INCOME_FAMILY_* faminc_*
rename YPOL_105_* polint_*
rename YPOL_110_* vote_*
rename YPOL_130_* vote_reg_* 
rename YPOL_130A_* vote_reg_prosp_* 
rename CVC_WKSWK_YR_ALL_04_XRND wkswk_2004
rename CVC_WKSWK_YR_ALL_06_XRND wkswk_2006
rename CVC_WKSWK_YR_ALL_08_XRND wkswk_2008
rename CVC_WKSWK_YR_ALL_10_XRND wkswk_2010

clonevar votep_2004 = vote_2004
clonevar votep_2008 = vote_2008

clonevar votec_2006 = vote_2006
clonevar votec_2010 = vote_2010


*recode citizenship
recode CV_CITIZEN_CURRENT_2004 (1=0 "citizen, born in US")(2/6=1 "else")(else=.), gen(citizen_2004)
recode CV_CITIZEN_CURRENT_2006 (1=0 "citizen, born in US")(2/6=1 "else")(else=.), gen(citizen_2006)
recode CV_CITIZEN_CURRENT_2008 (1=0 "citizen, born in US")(2/6=1 "else")(else=.), gen(citizen_2008)
recode CV_CITIZEN_CURRENT_2010 (1=0 "citizen, born in US")(2/6=1 "else")(else=.), gen(citizen_2010)

gen citizen = .
replace citizen = citizen_2004
replace citizen = citizen_2006 if citizen==. 
replace citizen = citizen_2008 if citizen==. 
replace citizen = citizen_2010 if citizen==. 

drop citizen_* CV_CITIZEN_CURRENT*

*gen constant family income when entering panel
clonevar inc_start = faminc_1997
mvdecode inc_start, mv(-48100 -8050 -7500)
gen inc_start_eq = inc_start/(sqrt(hhsize_1997))
xtile inc_start_cons = inc_start_eq, nq(10) 

*********************
* reshape data 
*********************

reshape long faminc_ hhsize_ polint_ vote_ votep_ votec_ vote_reg_ vote_reg_prosp_ wkswk_, ///																		
		i(pid) j(year) 

renvars faminc_ hhsize_ polint_ vote_ votep_ votec_ vote_reg_ vote_reg_prosp_ wkswk_, postdrop(1)



**********************
*** Recode data ******
**********************

drop if faminc<0

*sep
gen hhinc = faminc
gen hhinc_pp = hhinc/hhsize
gen hhinc_pp_sqrt = hhinc/(sqrt(hhsize))

xtile hhinc_dec = hhinc, nq(10) 
xtile hhinc_dec_pp = hhinc_pp, nq(10) 
xtile hhinc_dec_pp_sqrt = hhinc_pp_sqrt, nq(10) 

gen hhinc_dec10 = (hhinc_dec-1)*(10/9)
gen hhinc_dec_pp10 = (hhinc_dec_pp-1)*(10/9)
gen hhinc_dec_pp_sqrt10 = (hhinc_dec_pp_sqrt-1)*(10/9)


*political variables 
rename vote vote5
rename votep votep5
rename votec votec5

recode vote5 (1/3=0 "did not vote") (4=1 "voted")(else=.), gen(vote) 
recode votep5 (1/3=0 "did not vote") (4=1 "voted")(else=.), gen(votep) 
recode votec5 (1/3=0 "did not vote") (4=1 "voted")(else=.), gen(votec) 

recode polint (1=3 "most of the time")(2=2)(3=1)(4=0 "hardly at all")(else=.), gen(polint_r)
gen polint10 = polint_r*(10/3)


*socio-demographics
gen female = sex-1

fre wkswk

recode highest_degree (3/7=1 "college")(0/2=0 "hs or lower")(else=.), gen(college)

gen age = year-birthyear
recode age (13/25=1)(26/120=0)(else=.), gen(age1825)
recode age (13/35=1)(36/120=0)(else=.), gen(age1835)
gen age18 = age-18
center age, gen(age_c)

fre ethnicity
recode ethnicity (1=1 "black")(2/4=0 "other")(else=.), gen(black)
recode ethnicity (2 3=1 "black")(1 4=0 "other")(else=.), gen(race_other)

* dummy for election type
gen midterm = 0
replace midterm = 1 if year==2006 | year==2010


*save long
drop  wkswk_* polint_r

save "nlsy97_long.dta", replace










